# pscoreFun :: function that maximized balance estimating a pscore from a 
# 				subset of covariates given the indicator

pscoreFun=function(indicator){
	#called by genoud, and so needs objects tr & mMat
	options(warn=0)
	matTemp=as.matrix(mMat)%*%diag(indicator)
	matTemp=as.data.frame(cbind(tr,matTemp))
	zscore=(lm(formula(matTemp),data=matTemp)$fitted)
	
	aMat=matrix(NA,length(zscore),length(zscore))
	for(i in 1:length(zscore)){
		aMat[i,]=sqrt((zscore[i]-zscore)^2)+1
	}
	
	zMat=matrix(NA,length(tr),length(tr))
	for(i in 1:length(tr)){
		zMat[i,]=abs(tr[i]-tr)
	}
	zMat[which(zMat==0)]=.00001
	
	dMat=as.data.frame(as.matrix(aMat/zMat))
	
	outs=nbpGreedy(dMat=dMat)
	
	pvals=balFun(mMat=mMat,outs=outs,tr=tr)
	print(pvals)
	return(pvals)
}

#end